home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / grammar1.lha / c++grammar1.1 / c4.y next >
Text File  |  1990-06-06  |  25KB  |  835 lines

  1. %{
  2.  
  3.     /* Copyright (C) 1989,1990 James A. Roskind, All rights reserved.
  4.     This grammar was developed  and  written  by  James  A.  Roskind. 
  5.     Copying  of  this  grammar  description, as a whole, is permitted 
  6.     providing this notice is intact and applicable  in  all  complete 
  7.     copies.   Translations as a whole to other parser generator input 
  8.     languages  (or  grammar  description  languages)   is   permitted 
  9.     provided  that  this  notice is intact and applicable in all such 
  10.     copies,  along  with  a  disclaimer  that  the  contents  are   a 
  11.     translation.   The reproduction of derived text, such as modified 
  12.     versions of this grammar, or the output of parser generators,  is 
  13.     permitted,  provided  the  resulting  work includes the copyright 
  14.     notice "Portions Copyright (c)  1989,  1990  James  A.  Roskind". 
  15.     Derived products, such as compilers, translators, browsers, etc., 
  16.     that  use  this  grammar,  must also provide the notice "Portions 
  17.     Copyright  (c)  1989,  1990  James  A.  Roskind"  in   a   manner 
  18.     appropriate  to  the  utility,  and in keeping with copyright law 
  19.     (e.g.: EITHER displayed when first invoked/executed; OR displayed 
  20.     continuously on display terminal; OR via placement in the  object 
  21.     code  in  form  readable in a printout, with or near the title of 
  22.     the work, or at the end of the file).  No royalties, licenses  or 
  23.     commissions  of  any  kind are required to copy this grammar, its 
  24.     translations, or derivative products, when the copies are made in 
  25.     compliance with this notice. Persons or corporations that do make 
  26.     copies in compliance with this notice may charge  whatever  price 
  27.     is  agreeable  to  a  buyer, for such copies or derivative works. 
  28.     THIS GRAMMAR IS PROVIDED ``AS IS'' AND  WITHOUT  ANY  EXPRESS  OR 
  29.     IMPLIED  WARRANTIES,  INCLUDING,  WITHOUT LIMITATION, THE IMPLIED 
  30.     WARRANTIES  OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR 
  31.     PURPOSE.
  32.  
  33.     James A. Roskind
  34.     Independent Consultant
  35.     516 Latania Palm Drive
  36.     Indialantic FL, 32903
  37.     (407)729-4348
  38.     jar@ileaf.com
  39.     or ...!uunet!leafusa!jar
  40.  
  41.  
  42.     ---end of copyright notice---
  43.  
  44.  
  45. This file is a companion file to a C++ grammar description file.
  46.  
  47. */
  48.  
  49.  
  50. /* FILENAME: C.Y */
  51.  
  52. /*  This  is a grammar file for the dpANSI C language.  This file was 
  53. last modified by J. Roskind on 3/7/90. Version 1.00 */
  54.  
  55.  
  56.  
  57.  
  58. /* ACKNOWLEDGMENT:
  59.  
  60. Without the effort expended by the ANSI C standardizing committee,  I 
  61. would  have been lost.  Although the ANSI C standard does not include 
  62. a fully disambiguated syntax description, the committee has at  least 
  63. provided most of the disambiguating rules in narratives.
  64.  
  65. Several  reviewers  have also recently critiqued this grammar, and/or 
  66. assisted in discussions during it's preparation.  These reviewers are 
  67. certainly not responsible for the errors I have committed  here,  but 
  68. they  are responsible for allowing me to provide fewer errors.  These 
  69. colleagues include: Bruce Blodgett, and Mark Langley. */
  70.  
  71.  
  72. %}
  73.  
  74. /* This refined grammar resolves several typedef ambiguities  in  the 
  75. draft  proposed  ANSI  C  standard  syntax  down  to  1  shift/reduce 
  76. conflict, as reported by a YACC process.  Note  that  the  one  shift 
  77. reduce  conflicts  is the traditional if-if-else conflict that is not 
  78. resolved by the grammar.  This ambiguity can  be  removed  using  the 
  79. method  described in the Dragon Book (2nd edition), but this does not 
  80. appear worth the effort.
  81.  
  82. There was quite a bit of effort made to reduce the conflicts to  this 
  83. level,  and  an  additional effort was made to make the grammar quite 
  84. similar to the C++ grammar being developed in  parallel.   Note  that 
  85. this grammar resolves the following ANSI C ambiguity as follows:
  86.  
  87. ANSI  C  section  3.5.6,  "If  the [typedef name] is redeclared at an 
  88. inner scope, the type specifiers shall not be omitted  in  the  inner 
  89. declaration".   Supplying type specifiers prevents consideration of T 
  90. as a typedef name in this grammar.  Failure to supply type specifiers 
  91. forced the use of the TYPEDEFname as a type specifier.
  92.               
  93. ANSI C section 3.5.4.3, "In a parameter declaration, a single typedef 
  94. name in parentheses is  taken  to  be  an  abstract  declarator  that 
  95. specifies  a  function  with  a  single  parameter,  not as redundant 
  96. parentheses around the identifier".  This is extended  to  cover  the 
  97. following cases:
  98.  
  99. typedef float T;
  100. int noo(const (T[5]));
  101. int moo(const (T(int)));
  102. ...
  103.  
  104. Where  again the '(' immediately to the left of 'T' is interpreted as 
  105. being the start of a parameter type list,  and  not  as  a  redundant 
  106. paren around a redeclaration of T.  Hence an equivalent code fragment 
  107. is:
  108.  
  109. typedef float T;
  110. int noo(const int identifier1 (T identifier2 [5]));
  111. int moo(const int identifier1 (T identifier2 (int identifier3)));
  112. ...
  113.  
  114. */
  115.  
  116.  
  117.  
  118.  
  119. /* Define terminal tokens */
  120.  
  121.  
  122. /* keywords */
  123. %token AUTO            DOUBLE          INT             STRUCT
  124. %token BREAK           ELSE            LONG            SWITCH
  125. %token CASE            ENUM            REGISTER        TYPEDEF
  126. %token CHAR            EXTERN          RETURN          UNION
  127. %token CONST           FLOAT           SHORT           UNSIGNED
  128. %token CONTINUE        FOR             SIGNED          VOID
  129. %token DEFAULT         GOTO            SIZEOF          VOLATILE
  130. %token DO              IF              STATIC          WHILE
  131.  
  132. /* ANSI Grammar suggestions */
  133. %token IDENTIFIER              STRINGliteral
  134. %token FLOATINGconstant        INTEGERconstant        CHARACTERconstant
  135. %token OCTALconstant           HEXconstant
  136.  
  137. /* New Lexical element, whereas ANSI suggested non-terminal */
  138.  
  139. %token TYPEDEFname /* Lexer will tell the difference between this and 
  140.     an  identifier!   An  identifier  that is CURRENTLY in scope as a 
  141.     typedef name is provided to the parser as a TYPEDEFname.*/
  142.  
  143. /* Multi-Character operators */
  144. %token  ARROW            /*    ->                              */
  145. %token  ICR DECR         /*    ++      --                      */
  146. %token  LS RS            /*    <<      >>                      */
  147. %token  LE GE EQ NE      /*    <=      >=      ==      !=      */
  148. %token  ANDAND OROR      /*    &&      ||                      */
  149. %token  ELLIPSIS         /*    ...                             */
  150.  
  151. /* modifying assignment operators */
  152. %token MULTassign  DIVassign    MODassign   /*   *=      /=      %=      */
  153. %token PLUSassign  MINUSassign              /*   +=      -=              */
  154. %token LSassign    RSassign                 /*   <<=     >>=             */
  155. %token ANDassign   ERassign     ORassign    /*   &=      ^=      |=      */
  156.  
  157. %start prog.start
  158.  
  159. %%
  160. prog.start:
  161.         translation.unit
  162.         ;
  163.  
  164. /* CONSTANTS */
  165. constant:
  166.         FLOATINGconstant
  167.         | INTEGERconstant
  168.         /* We are not including ENUMERATIONconstant here  because  we 
  169.         are  treating  it like a variable with a type of "enumeration 
  170.         constant".  */
  171.         | OCTALconstant
  172.         | HEXconstant
  173.         | CHARACTERconstant
  174.         ;
  175.  
  176. /* STRING LITERALS */
  177. string.literal.list:
  178.                 STRINGliteral
  179.                 | string.literal.list STRINGliteral
  180.                 ;
  181.  
  182.  
  183. /* EXPRESSIONS */
  184. primary.expression:
  185.         IDENTIFIER  /* We cannot use a typedef name as a variable */
  186.         | constant
  187.         | string.literal.list
  188.         | '(' expression ')'
  189.         ;
  190.  
  191. postfix.expression:
  192.         primary.expression
  193.         | postfix.expression '[' expression ']'
  194.         | postfix.expression '(' ')'
  195.         | postfix.expression '(' argument.expression.list ')'
  196.         | postfix.expression '.' identifier.or.typedef.name
  197.         | postfix.expression ARROW identifier.or.typedef.name
  198.         | postfix.expression ICR
  199.         | postfix.expression DECR
  200.         ;
  201.  
  202. argument.expression.list:
  203.         assignment.expression
  204.         | argument.expression.list ',' assignment.expression
  205.         ;
  206.  
  207. unary.expression:
  208.         postfix.expression
  209.         | ICR unary.expression
  210.         | DECR unary.expression
  211.         | unary.operator cast.expression
  212.         | SIZEOF unary.expression
  213.         | SIZEOF '(' type.name ')'
  214.         ;
  215.  
  216. unary.operator:
  217.         '&'
  218.         | '*'
  219.         | '+'
  220.         | '-'
  221.         | '~'
  222.         | '!'
  223.         ;
  224.  
  225. cast.expression:
  226.         unary.expression
  227.         | '(' type.name ')' cast.expression
  228.         ;
  229.  
  230. multiplicative.expression:
  231.         cast.expression
  232.         | multiplicative.expression '*' cast.expression
  233.         | multiplicative.expression '/' cast.expression
  234.         | multiplicative.expression '%' cast.expression
  235.         ;
  236.  
  237. additive.expression:
  238.         multiplicative.expression
  239.         | additive.expression '+' multiplicative.expression
  240.         | additive.expression '-' multiplicative.expression
  241.         ;
  242.  
  243. shift.expression:
  244.         additive.expression
  245.         | shift.expression LS additive.expression
  246.         | shift.expression RS additive.expression
  247.         ;
  248.  
  249. relational.expression:
  250.         shift.expression
  251.         | relational.expression '<' shift.expression
  252.         | relational.expression '>' shift.expression
  253.         | relational.expression LE shift.expression
  254.         | relational.expression GE shift.expression
  255.         ;
  256.  
  257. equality.expression:
  258.         relational.expression
  259.         | equality.expression EQ relational.expression
  260.         | equality.expression NE relational.expression
  261.         ;
  262.  
  263. AND.expression:
  264.         equality.expression
  265.         | AND.expression '&' equality.expression
  266.         ;
  267.  
  268. exclusive.OR.expression:
  269.         AND.expression
  270.         | exclusive.OR.expression '^' AND.expression
  271.         ;
  272.  
  273. inclusive.OR.expression:
  274.         exclusive.OR.expression
  275.         | inclusive.OR.expression '|' exclusive.OR.expression
  276.         ;
  277.  
  278. logical.AND.expression:
  279.         inclusive.OR.expression
  280.         | logical.AND.expression ANDAND inclusive.OR.expression
  281.         ;
  282.  
  283. logical.OR.expression:
  284.         logical.AND.expression
  285.         | logical.OR.expression OROR logical.AND.expression
  286.         ;
  287.  
  288. conditional.expression:
  289.         logical.OR.expression
  290.         | logical.OR.expression '?' expression ':'
  291.                 conditional.expression
  292.         ;
  293.  
  294. assignment.expression:
  295.         conditional.expression
  296.         | unary.expression assignment.operator assignment.expression
  297.         ;
  298.  
  299. assignment.operator:
  300.         '='
  301.         | MULTassign
  302.         | DIVassign
  303.         | MODassign
  304.         | PLUSassign
  305.         | MINUSassign
  306.         | LSassign
  307.         | RSassign
  308.         | ANDassign
  309.         | ERassign
  310.         | ORassign
  311.         ;
  312.  
  313. expression:
  314.         assignment.expression
  315.         | expression ',' assignment.expression
  316.         ;
  317.  
  318. constant.expression:
  319.         conditional.expression
  320.         ;
  321.  
  322.     /* The following was used for clarity */
  323. expression.opt:
  324.         /* Nothing */
  325.         | expression
  326.         ;
  327.  
  328.  
  329.  
  330. /* DECLARATIONS */
  331.  
  332.     /* The following is different from the ANSI C specified  grammar.  
  333.     The  changes  were  made  to  disambiguate  typedef's presence in 
  334.     declaration.specifiers (vs.  in the declarator for redefinition); 
  335.     to allow struct/union/enum tag declarations without  declarators, 
  336.     and  to  better  reflect the parsing of declarations (declarators 
  337.     must be combined with declaration.specifiers ASAP  so  that  they 
  338.     are visible in scope).
  339.  
  340.     Example  of  typedef  use  as either a declaration.specifier or a 
  341.     declarator:
  342.  
  343.       typedef int T;
  344.       struct S { T T;}; /* redefinition of T as member name * /
  345.  
  346.     Example of legal and illegal statements detected by this grammar:
  347.  
  348.       int; /* syntax error: vacuous declaration * /
  349.       struct S;  /* no error: tag is defined or elaborated * /
  350.  
  351.     Example of result of proper declaration binding:
  352.         
  353.         int a=sizeof(a); /* note that "a" is declared with a type  in 
  354.             the name space BEFORE parsing the initializer * /
  355.  
  356.         int b, c[sizeof(b)]; /* Note that the first declarator "b" is 
  357.              declared  with  a  type  BEFORE the second declarator is 
  358.              parsed * /
  359.  
  360.     */
  361.  
  362. declaration:
  363.         sue.declaration.specifier ';'
  364.         | sue.type.specifier ';'
  365.         | declaring.list ';'
  366.         | default.declaring.list ';'
  367.         ;
  368.  
  369.     /* Note that if a typedef were  redeclared,  then  a  declaration 
  370.     specifier must be supplied */
  371.  
  372. default.declaring.list:  /* Can't  redeclare typedef names */
  373.         declaration.qualifier.list identifier.declarator {} initializer.opt
  374.         | type.qualifier.list identifier.declarator {} initializer.opt
  375.         | default.declaring.list ',' identifier.declarator {} initializer.opt
  376.         ;
  377.  
  378. declaring.list:
  379.         declaration.specifier declarator {} initializer.opt
  380.         | type.specifier declarator {} initializer.opt
  381.         | declaring.list ',' declarator {} initializer.opt
  382.         ;
  383.  
  384. declaration.specifier:
  385.         basic.declaration.specifier        /* Arithmetic or void */
  386.         | sue.declaration.specifier          /* struct/union/enum */
  387.         | typedef.declaration.specifier      /* typedef*/
  388.         ;
  389.  
  390. type.specifier:
  391.         basic.type.specifier                 /* Arithmetic or void */
  392.         | sue.type.specifier                 /* Struct/Union/Enum */
  393.         | typedef.type.specifier             /* Typedef */
  394.         ;
  395.  
  396.  
  397. declaration.qualifier.list:  /* const/volatile, AND storage class */
  398.         storage.class
  399.         | type.qualifier.list storage.class
  400.         | declaration.qualifier.list declaration.qualifier
  401.         ;
  402.  
  403. type.qualifier.list:
  404.         type.qualifier
  405.         | type.qualifier.list type.qualifier
  406.         ;
  407.  
  408. declaration.qualifier:
  409.         type.qualifier                  /* const or volatile */
  410.         | storage.class
  411.         ;
  412.  
  413. type.qualifier:
  414.         CONST
  415.         | VOLATILE
  416.         ;
  417.  
  418. basic.declaration.specifier:      /*StorageClass+Arithmetic or void*/
  419.         basic.type.specifier  storage.class
  420.         | declaration.qualifier.list basic.type.name
  421.         | basic.declaration.specifier declaration.qualifier
  422.         | basic.declaration.specifier basic.type.name
  423.         ;
  424.  
  425. basic.type.specifier:
  426.         basic.type.name            /* Arithmetic or void */
  427.         | type.qualifier.list basic.type.name
  428.         | basic.type.specifier type.qualifier
  429.         | basic.type.specifier basic.type.name
  430.         ;
  431.  
  432. sue.declaration.specifier:          /* StorageClass + struct/union/enum */
  433.         sue.type.specifier storage.class
  434.         | declaration.qualifier.list elaborated.type.name
  435.         | sue.declaration.specifier declaration.qualifier
  436.         ;
  437.  
  438. sue.type.specifier:
  439.         elaborated.type.name              /* struct/union/enum */
  440.         | type.qualifier.list elaborated.type.name
  441.         | sue.type.specifier type.qualifier
  442.         ;
  443.  
  444.  
  445. typedef.declaration.specifier:       /*Storage Class + typedef types */
  446.         typedef.type.specifier storage.class
  447.         | declaration.qualifier.list TYPEDEFname
  448.         | typedef.declaration.specifier declaration.qualifier
  449.         ;
  450.  
  451. typedef.type.specifier:              /* typedef types */
  452.         TYPEDEFname
  453.         | type.qualifier.list TYPEDEFname
  454.         | typedef.type.specifier type.qualifier
  455.         ;
  456.  
  457. storage.class:
  458.         TYPEDEF
  459.         | EXTERN
  460.         | STATIC
  461.         | AUTO
  462.         | REGISTER
  463.         ;
  464.  
  465. basic.type.name:
  466.         VOID
  467.         | CHAR
  468.         | SHORT
  469.         | INT
  470.         | LONG
  471.         | FLOAT
  472.         | DOUBLE
  473.         | SIGNED
  474.         | UNSIGNED
  475.         ;
  476.  
  477. elaborated.type.name:
  478.         struct.or.union.specifier
  479.         | enum.specifier
  480.         ;
  481.  
  482. struct.or.union.specifier:
  483.         struct.or.union '{' struct.declaration.list '}'
  484.         | struct.or.union identifier.or.typedef.name
  485.                 '{' struct.declaration.list '}'
  486.         | struct.or.union identifier.or.typedef.name
  487.         ;
  488.  
  489. struct.or.union:
  490.         STRUCT
  491.         | UNION
  492.         ;
  493.  
  494. struct.declaration.list:
  495.         struct.declaration
  496.         | struct.declaration.list struct.declaration
  497.         ;
  498.  
  499. struct.declaration:
  500.         struct.declaring.list ';'
  501.         | struct.default.declaring.list ';'
  502.         ;
  503.  
  504. struct.default.declaring.list:        /* doesn't redeclare typedef*/
  505.         type.qualifier.list struct.identifier.declarator
  506.         | struct.default.declaring.list ',' struct.identifier.declarator
  507.         ;
  508.  
  509. struct.declaring.list:        
  510.         type.specifier struct.declarator
  511.         | struct.declaring.list ',' struct.declarator
  512.         ;
  513.  
  514.  
  515. struct.declarator:
  516.         declarator bit.field.size.opt
  517.         | bit.field.size
  518.         ;
  519.  
  520. struct.identifier.declarator:
  521.         identifier.declarator bit.field.size.opt
  522.         | bit.field.size
  523.         ;
  524.  
  525. bit.field.size.opt:
  526.         /* nothing */
  527.         | bit.field.size
  528.         ;
  529.  
  530. bit.field.size:
  531.         ':' constant.expression
  532.         ;
  533.  
  534. enum.specifier:
  535.         ENUM '{' enumerator.list '}'
  536.         | ENUM identifier.or.typedef.name '{' enumerator.list '}'
  537.         | ENUM identifier.or.typedef.name
  538.         ;
  539.  
  540.  
  541.  
  542. enumerator.list:
  543.         identifier.or.typedef.name enumerator.value.opt
  544.         | enumerator.list ',' identifier.or.typedef.name enumerator.value.opt
  545.         ;
  546.  
  547. enumerator.value.opt:
  548.         /* Nothing */
  549.         | '=' constant.expression
  550.         ;
  551.  
  552. parameter.type.list:
  553.         parameter.list
  554.         | parameter.list ',' ELLIPSIS
  555.         ;
  556.  
  557. parameter.list:
  558.         parameter.declaration
  559.         | parameter.list ',' parameter.declaration
  560.         ;
  561.  
  562. parameter.declaration:
  563.         declaration.specifier
  564.         | declaration.specifier abstract.declarator
  565.         | declaration.specifier identifier.declarator
  566.         | declaration.specifier parameter.typedef.declarator
  567.         | declaration.qualifier.list 
  568.         | declaration.qualifier.list abstract.declarator
  569.         | declaration.qualifier.list identifier.declarator
  570.         | type.specifier
  571.         | type.specifier abstract.declarator
  572.         | type.specifier identifier.declarator
  573.         | type.specifier parameter.typedef.declarator
  574.         | type.qualifier.list 
  575.         | type.qualifier.list abstract.declarator
  576.         | type.qualifier.list identifier.declarator
  577.         ;
  578.  
  579.     /*  ANSI  C  section  3.7.1  states  "An identifier declared as a 
  580.     typedef name shall not be redeclared as a parameter".  Hence  the 
  581.     following is based only on IDENTIFIERs */
  582.  
  583. identifier.list:
  584.         IDENTIFIER
  585.         | identifier.list ',' IDENTIFIER
  586.         ;
  587.  
  588. identifier.or.typedef.name:
  589.         IDENTIFIER
  590.         | TYPEDEFname
  591.         ;
  592.  
  593. type.name:
  594.         type.specifier
  595.         | type.specifier abstract.declarator
  596.         | type.qualifier.list 
  597.         | type.qualifier.list abstract.declarator
  598.         ;
  599.  
  600. initializer.opt:
  601.         /* nothing */
  602.         | '=' initializer
  603.         ;
  604.  
  605. initializer:
  606.         '{' initializer.list '}'
  607.         | '{' initializer.list ',' '}'
  608.         | assignment.expression
  609.         ;
  610.  
  611. initializer.list:
  612.         initializer
  613.         | initializer.list ',' initializer
  614.         ;
  615.  
  616.  
  617. /* STATEMENTS */
  618. statement:
  619.         labeled.statement
  620.         | compound.statement
  621.         | expression.statement
  622.         | selection.statement
  623.         | iteration.statement
  624.         | jump.statement
  625.         ;
  626.  
  627. labeled.statement:
  628.         identifier.or.typedef.name ':' statement
  629.         | CASE constant.expression ':' statement
  630.         | DEFAULT ':' statement
  631.         ;
  632.  
  633. compound.statement:
  634.         '{' '}'
  635.         | '{' declaration.list '}'
  636.         | '{' statement.list '}'
  637.         | '{' declaration.list statement.list '}'
  638.         ;
  639.  
  640. declaration.list:
  641.         declaration
  642.         | declaration.list declaration
  643.         ;
  644.  
  645. statement.list:
  646.         statement
  647.         | statement.list statement
  648.         ;
  649.  
  650. expression.statement:
  651.         expression.opt ';'
  652.         ;
  653.  
  654. selection.statement:
  655.         IF '(' expression ')' statement
  656.         | IF '(' expression ')' statement ELSE statement
  657.         | SWITCH '(' expression ')' statement
  658.         ;
  659.  
  660. iteration.statement:
  661.         WHILE '(' expression ')' statement
  662.         | DO statement WHILE '(' expression ')' ';'
  663.         | FOR '(' expression.opt ';' expression.opt ';'
  664.                 expression.opt ')' statement
  665.         ;
  666.  
  667. jump.statement:
  668.         GOTO identifier.or.typedef.name ';'
  669.         | CONTINUE ';'
  670.         | BREAK ';'
  671.         | RETURN expression.opt ';'
  672.         ;
  673.  
  674.  
  675. /* EXTERNAL DEFINITIONS */
  676.  
  677. translation.unit:
  678.         external.definition
  679.         | translation.unit external.definition
  680.         ;
  681.  
  682. external.definition:
  683.         function.definition
  684.         | declaration
  685.         ;
  686.  
  687. function.definition:
  688.                                      identifier.declarator compound.statement
  689.         | declaration.specifier      identifier.declarator compound.statement
  690.         | type.specifier             identifier.declarator compound.statement
  691.         | declaration.qualifier.list identifier.declarator compound.statement
  692.         | type.qualifier.list        identifier.declarator compound.statement
  693.  
  694.         |                            old.function.declarator compound.statement 
  695.         | declaration.specifier      old.function.declarator compound.statement
  696.         | type.specifier             old.function.declarator compound.statement
  697.         | declaration.qualifier.list old.function.declarator compound.statement
  698.         | type.qualifier.list        old.function.declarator compound.statement
  699.  
  700.         |                            old.function.declarator declaration.list 
  701.                 compound.statement
  702.         | declaration.specifier      old.function.declarator declaration.list
  703.                 compound.statement
  704.         | type.specifier             old.function.declarator declaration.list
  705.                 compound.statement
  706.         | declaration.qualifier.list old.function.declarator declaration.list
  707.                 compound.statement
  708.         | type.qualifier.list        old.function.declarator declaration.list
  709.                 compound.statement
  710.         ;
  711.  
  712. declarator:
  713.         typedef.declarator
  714.         | identifier.declarator
  715.         ;
  716.  
  717. typedef.declarator:
  718.         paren.typedef.declarator  /* would be ambiguous as parameter*/
  719.         | parameter.typedef.declarator   /* not ambiguous as param*/
  720.         ;
  721.  
  722. parameter.typedef.declarator:
  723.         TYPEDEFname 
  724.         | TYPEDEFname postfixing.abstract.declarator
  725.         | clean.typedef.declarator
  726.         ;
  727.  
  728.     /*  The  following have at least one '*'. There is no (redundant) 
  729.     '(' between the '*' and the TYPEDEFname. */
  730.  
  731. clean.typedef.declarator:
  732.         clean.postfix.typedef.declarator
  733.         | '*' parameter.typedef.declarator
  734.         | '*' type.qualifier.list parameter.typedef.declarator  
  735.         ;
  736.  
  737. clean.postfix.typedef.declarator:
  738.         '(' clean.typedef.declarator ')'
  739.         | '(' clean.typedef.declarator ')' postfixing.abstract.declarator
  740.         ;
  741.  
  742.     /* The following have a redundant '(' placed immediately  to  the 
  743.     left of the TYPEDEFname */
  744.  
  745. paren.typedef.declarator:
  746.         paren.postfix.typedef.declarator
  747.         | '*' '(' simple.paren.typedef.declarator ')' /* redundant paren */
  748.         | '*' type.qualifier.list  
  749.                 '(' simple.paren.typedef.declarator ')' /* redundant paren */
  750.         | '*' paren.typedef.declarator
  751.         | '*' type.qualifier.list paren.typedef.declarator
  752.         ;
  753.         
  754. paren.postfix.typedef.declarator: /* redundant paren to left of tname*/
  755.         '(' paren.typedef.declarator ')'
  756.         | '(' simple.paren.typedef.declarator postfixing.abstract.declarator ')' /* redundant paren */
  757.         | '(' paren.typedef.declarator ')' postfixing.abstract.declarator
  758.         ;
  759.  
  760. simple.paren.typedef.declarator:
  761.         TYPEDEFname
  762.         | '(' simple.paren.typedef.declarator ')'
  763.         ;
  764.  
  765. identifier.declarator:
  766.         unary.identifier.declarator
  767.         | paren.identifier.declarator
  768.         ;
  769.  
  770. unary.identifier.declarator:
  771.         postfix.identifier.declarator
  772.         | '*' identifier.declarator
  773.         | '*' type.qualifier.list identifier.declarator
  774.         ;
  775.         
  776. postfix.identifier.declarator:
  777.         paren.identifier.declarator postfixing.abstract.declarator
  778.         | '(' unary.identifier.declarator ')'
  779.         | '(' unary.identifier.declarator ')' postfixing.abstract.declarator
  780.         ;
  781.  
  782. paren.identifier.declarator:
  783.         IDENTIFIER
  784.         | '(' paren.identifier.declarator ')'
  785.         ;
  786.  
  787. old.function.declarator:
  788.         postfix.old.function.declarator
  789.         | '*' old.function.declarator
  790.         | '*' type.qualifier.list old.function.declarator
  791.         ;
  792.  
  793. postfix.old.function.declarator:
  794.         paren.identifier.declarator '(' identifier.list ')'
  795.         | '(' old.function.declarator ')'
  796.         | '(' old.function.declarator ')' postfixing.abstract.declarator
  797.         ;
  798.  
  799. abstract.declarator:
  800.         unary.abstract.declarator
  801.         | postfix.abstract.declarator
  802.         | postfixing.abstract.declarator
  803.         ;
  804.  
  805. postfixing.abstract.declarator:
  806.         array.abstract.declarator
  807.         | '(' ')'
  808.         | '(' parameter.type.list ')'
  809.         ;
  810.  
  811. array.abstract.declarator:
  812.         '[' ']'
  813.         | '[' constant.expression ']'
  814.         | array.abstract.declarator '[' constant.expression ']'
  815.         ;
  816.  
  817. unary.abstract.declarator:
  818.         '*' 
  819.         | '*' type.qualifier.list 
  820.         | '*' abstract.declarator
  821.         | '*' type.qualifier.list abstract.declarator
  822.         ;
  823.  
  824. postfix.abstract.declarator:
  825.         '(' unary.abstract.declarator ')'
  826.         | '(' postfix.abstract.declarator ')'
  827.         | '(' postfixing.abstract.declarator ')'
  828.         | '(' unary.abstract.declarator ')' postfixing.abstract.declarator
  829.         ;
  830.  
  831. %%
  832. /* ----end of grammar----*/
  833.  
  834.  
  835.